package cn.scantd.core.util;

import org.eclipse.jdt.core.dom.Modifier;

import cn.scantd.core.attrs.Scope;

public class EnumUtil {

    public static Scope getScope(int modifier) {
        if (Modifier.isPublic(modifier)) {
            return Scope.PUBLIC;
        } else if (Modifier.isProtected(modifier)) {
            return Scope.PROTECTED;
        } else if (Modifier.isDefault(modifier)) {
            return Scope.DEFAULT;
        } else if (Modifier.isPrivate(modifier)) {
            return Scope.PRIVATE;
        } else {
            return Scope.DEFAULT;
        }
    }
    
    public static boolean canRead(Scope scope, Scope curr) {
        if (Scope.PRIVATE.equals(scope)) {
            return true;
        } else if (Scope.DEFAULT.equals(scope)) {
            if (Scope.PRIVATE.equals(curr)) {
                return false;
            } else {
                return true;
            }
        } else if (Scope.PROTECTED.equals(scope)) {
            if (Scope.PUBLIC.equals(curr) || Scope.PROTECTED.equals(curr)) {
                return true;
            } else {
                return false;
            }
        } else if (Scope.PUBLIC.equals(scope)) {
            if (Scope.PUBLIC.equals(curr)) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
        
    }
    
}
